<template lang="html">
  <div class="wrap_body">
    <div class="page-search" style="padding-top:45px;display: block;">
      <header>
        <div class="form">
    	<form action="#">
            <input type="text" v-model="keywords" id="keyword"  class="shb" placeholder="搜索目的地国家/城市/关键词" style="height: 30px; line-height: 30px;">
            <img v-show='tufag' @click="tolist(keywords)" src="http://m.caissa.com.cn/static/img/search.png" id="begin-search" style="right: 15px;"><a @click="history()" href="javascript:void(0);" id="hot-cancel-search">取消</a>
    	</form>
        </div>
      </header>
      <main>
        <section id="hot">
          <h2>热门搜索</h2>
          <ul class="clearfix">
            <li v-for="item in msg"><a @click="tolist(item.hotTerm)" href="javascript:void(0);">{{item.hotTerm}}</a></li>
          </ul>
        </section>
        <section id="history" v-show="isoff">
          <h2>历史搜索</h2>
          <ul>
            <li v-for="ks in words"><a href="javascript:void(0);">{{ks}}</a></li>
          </ul>
          <a href="javascript:void(0);" @click="clear()" id="clearHistorySearch">清除搜索记录</a>
        </section>
      </main>
    </div>
  </div>
</template>

<script>
import {localMessage} from '../js/localStorage'
export default {
  data(){
    return {
      msg:[],
      words:[],
      isoff:false,
      keywords:'',
      tufag:true
    }
  },
  methods: {
    history(){
      history.back();
    },
    tolist(word){
      console.log(word);
      // this.ciwords.push(word);
      // console.log("次次次" + this.ciwords);
      localMessage.pushArray('kyword',word);
      this.$router.push({
        path:'/tour1',
        query:{
          name:word
        }
      })
    },
    clear(){
      localMessage.clear('kyword');
      this.isoff = false;
      // this.ciwords = null;
      // this.ciwords = [];
      // console.log(this.ciwords);
    }
  },
  created(){
    this.axios.get('http://txspring.cn:8080/reci').then(res=>{
      console.log(res);
      if (!res.data.resultmsg.code) {
        this.msg = res.data.hotTerms;
        console.log(localMessage);
        let data = localMessage.getArray('kyword');
        if (data.length>0) {
          this.isoff = true;
          console.log("111"+data);
          this.words = data;
        }else {
          this.isoff = false;
        }
      }else {
        console.log(res.data.resultmsg.msg);
      }
    })
  },
  watch: {
      '$route'(newValue, oldValue){
          // this.user = newValue.query.name
          console.log(newValue);
          console.log(oldValue);
      }
  },
}
</script>

<style lang="css" scoped>
body {
    max-width: 640px;
    background: #f5f5f5;
    min-width: 300px;
    margin: 0 auto;
    padding: 0px;
}
header {
  width: 100%;
  position: fixed;
  z-index: 91;
  top: 0;
  background-color: #00b0ec;
  height: 50px;
}
.page-search header .form {
    left: 35px;
    right: 75px;
    position: absolute;
    top: 8px;
    border: 0 none;
}
.page-search form {
    top: 0;
    left: 0;
    right: 0;
    width: 95%;
}
.shb {
    border-radius: 5px;
    color: #999;
    height: 24px;
    line-height: 24px;
    padding: 5px 5px 5px 10px;
    width: 100%;
    border: 0 none;
}
.page-search form img, .page-list form img, .page-search .form img {
    cursor: pointer;
    position: absolute;
    right: 2px;
    top: 6px;
    width: 20px;
}
.page-search .form a {
    color: #fff;
    position: absolute;
    right: -50px;
    top: 7px;
}
.page-search main {
    margin-top: 0;
    height: 90%;
    overflow: auto;
}
.page-search section {
    padding: 20px 35px;
}
.page-search h2 {
    color: #999;
    font-size: 1em;
    font-weight: normal;
    margin-bottom: 5px;
}
.page-search #hot li {
    float: left;
    font-size: 0.9em;
    line-height: 25px;
    margin: 5px 1% 0;
    text-align: center;
    width: 30%;
    border: 1px solid #00b0ec;
    border-radius: 6px;
}
.page-search #hot li a {
    color: #006fba;
    font-size: .9em;
}
.page-search #history h2 {
    margin-bottom: 0;
    padding-bottom: 15px;
    border-bottom: 1px solid #e6e9ed;
}
.page-search h2 {
    color: #999;
    font-size: 1em;
    font-weight: normal;
    margin-bottom: 5px;
}
.page-search #history > a {
    background-color: #00b0ec;
    border-radius: 6px;
    color: #fff;
    display: block;
    line-height: 35px;
    margin: 15px 15px 0;
    text-align: center;
    width: 90%;
}
.page-search #history li a {
    border-bottom: 1px solid #e6e9ed;
    color: #333;
    display: block;
    line-height: 35px;
    font-size: .9em;
    text-align: left;
}
</style>
